package Lab5.AbstractMonster;

import lombok.Data;

import java.util.Random;

@Data
public abstract class Monster {
    protected double spAttackProbability = 0.2;
    protected String name;
    protected Random random;

    public Monster(String name) {
        setRandom(new Random());
        setName(name);
    }

    public Monster(String name, int spAttackProbability) {
        this(name);
        setSpAttackProbability(spAttackProbability);
    }

    public int attack() {
        if (random.nextDouble() < 0.2) {
            return specialAttack();
        } else {
            int randomNum = this.random.nextInt(5) + 1;
            System.out.printf("%s, of type %s,attacks generically: %d points damage caused.\n", this.name, this.getClass(), randomNum);
            return randomNum;
        }

    }

    protected abstract int specialAttack();

    public void move(int direction) {
        switch (direction) {
            case 1 -> System.out.println(this.name + "is moving 1step NORTH.");
            case 2 -> System.out.println(this.name + "is moving 1step EAST.");
            case 3 -> System.out.println(this.name + "is moving 1step SOUTH.");
            default -> System.out.println(this.name + "is moving 1step WEST.");
        }
    }


}
